//
//  LeftDrawerViewController.m
//  ZhihunewPaper
//
//  Created by 梅杰 on 16/7/8.
//  Copyright © 2016年 梅杰. All rights reserved.
//

#import "LeftDrawerViewController.h"
#import "LeftDrawTableViewCell.h"
#import "UserViewController.h"
#import "AppDelegate.h"
#import "HttpsManager.h"
#define CellHeight [@"test" sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:16],NSFontAttributeName, nil]].height + 30
@interface LeftDrawerViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIButton *userHeadButton;
@property (strong ,nonatomic) NSMutableArray *itemArray;
@end

@implementation LeftDrawerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.userHeadButton addTarget:self action:@selector(userButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
//    [self.navigationController setNavigationBarHidden:NO animated:NO];
    
}
- (void) netRequestThemes {
    NSString *urlString = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"interface.plist" ofType:nil]][@"themes"];
//    NSURL *url = [NSURL URLWithString:urlString];
    [HttpsManager getUrlDataWithUrl:urlString Param:nil Success:^(NSDictionary * _Nonnull dict, Boolean flag) {
        
    } fail:^(NSError * _Nonnull error) {
        NSLog(@"主题信息加载失败");
    }];
}
- (NSMutableArray *)itemArray{
    if (_itemArray == nil) {
        NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
        NSArray *array1 = [NSArray arrayWithObjects:@"主页",@"电影日报",@"用户推荐日报",@"日常心理学",@"不许无聊",@"设计日报",@"大公司日报",@"财经日报",@"互联网安全",@"开始游戏",@"音乐日报",@"动漫日报",@"体育日报", nil];
        [array addObjectsFromArray:array1];
        _itemArray = array;
    }
    return _itemArray;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.itemArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ident = @"cellIdent";
    LeftDrawTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ident];
    if (!cell) {
        cell = [[LeftDrawTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ident];
        cell.conLableButton.titleLabel.font = [UIFont systemFontOfSize:16];
    }
    [cell.conLableButton setTitle:[self.itemArray objectAtIndex:indexPath.row] forState:UIControlStateNormal];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    //这是一段宏定义
    return CellHeight;
}

#pragma mark 按钮的相应方法
- (void)userButtonClicked: (UIButton *) sender{
    UserViewController *userVC = [[UserViewController alloc] init];
//    UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:self];
    AppDelegate *appDeleagte = [UIApplication sharedApplication].delegate;
    UINavigationController *mainNAVC = (UINavigationController *)appDeleagte.mmDrawer.centerViewController;
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    
    backItem.title = @"";
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:20/255.0 green:155/255.0 blue:213/255.0 alpha:1.0]];
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    
    [mainNAVC.viewControllers.firstObject.navigationItem setBackBarButtonItem: backItem];
    [mainNAVC.viewControllers.firstObject.navigationController pushViewController:userVC animated:YES];
//    [self presentViewController:userVC animated:YES completion:nil];
}

//让cell点击后立即结束
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
